package com.leetcode;

/**
 * 812. 最大三角形面积
 * 枚举求解三角形最大面积
 *
 * @author fy
 * @date 2022-05-15 22:09
 */
public class Solution812 {

    public double largestTriangleArea(int[][] points) {
        int n = points.length;
        double res = 0.0d;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = j + 1; k < n; k++) {
                    res = Math.max(res, triangleArea(
                            points[i][0], points[i][1],
                            points[j][0], points[j][1],
                            points[k][0], points[k][1])
                    );
                }
            }
        }
        return res;
    }

    /**
     * 三角形面积的公式
     */
    private double triangleArea(int x1, int y1, int x2, int y2, int x3, int y3) {
        return 0.5 * Math.abs(x1 * y2 + x2 * y3 + x3 * y1 - x1 * y3 - x2 * y1 - x3 * y2);
    }

}
